<?php

namespace backend\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\models\AdminUser;

/**
 * AdminUserSearch represents the model behind the search form about `backend\models\Check`.
 */
class CheckSearch extends Check
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name','project_name'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function searchPurchaseYes($params)
    {
        $query = Check::find()->alias('a')->select(['a.*','b.project_name'])->LeftJoin('zj_project b','a.pid = b.id')->where(
            ['and' ,
                ['=' , 'a.type' , 1] ,
                ['=' , 'a.status' , 2] ,
            ]
        );

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
              ->andFilterWhere(['like', 'b.project_name', $this->project_name]);
        return $dataProvider;
    }

    public function searchPurchaseNo($params)
    {
        $query = Check::find()->alias('a')->select(['a.*','b.project_name'])->LeftJoin('zj_project b','a.pid = b.id')->where(
            ['and' ,
                ['=' , 'a.type' , 1] ,
                ['=' , 'a.status' , 3] ,
            ]
        );

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
            ->andFilterWhere(['like', 'b.project_name', $this->project_name]);
        return $dataProvider;
    }
    public function searchPurchaseNever($params)
    {
        $query = Check::find()->alias('a')->select(['a.*','b.project_name'])->LeftJoin('zj_project b','a.pid = b.id')->where(
            ['and' ,
                ['=' , 'a.type' , 1] ,
                ['=' , 'a.status' , 1] ,
            ]
        );

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
            ->andFilterWhere(['like', 'b.project_name', $this->project_name]);
        return $dataProvider;
    }
    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function searchAllocateYes($params)
    {
        $query = Check::find()->alias('a')
            ->select(['a.*','b.project_name p_name','b.name p_leader','c.name b_leader','c.project_name b_name'])
            ->LeftJoin('zj_project_user b','a.pid = b.id')
            ->LeftJoin('zj_project_user c','c.id = a.bid')
            ->where(
                ['and' ,
                    ['=' , 'a.type' , 2] ,
                    ['=' , 'a.status' , 2] ,
                ]
        );


        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name]);
        return $dataProvider;
    }
    public function searchAllocateNo($params)
    {
        $query = Check::find()->alias('a')
            ->select(['a.*','b.project_name p_name','b.name p_leader','c.name b_leader','c.project_name b_name'])
            ->LeftJoin('zj_project_user b','a.pid = b.id')
            ->LeftJoin('zj_project_user c','c.id = a.bid')
            ->where(
                ['and' ,
                    ['=' , 'a.type' , 2] ,
                    ['=' , 'a.status' , 3] ,
                ]
            );


        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name]);
        return $dataProvider;
    }
    public function searchAllocateNever($params)
    {
        $query = Check::find()->alias('a')
            ->select(['a.*','b.project_name p_name','b.name p_leader','c.name b_leader','c.project_name b_name'])
            ->LeftJoin('zj_project_user b','a.pid = b.id')
            ->LeftJoin('zj_project_user c','c.id = a.bid')
            ->where(
                ['and' ,
                    ['=' , 'a.type' , 2] ,
                    ['=' , 'a.status' , 1] ,
                ]
            );


        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name]);
        return $dataProvider;
    }
    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function searchScrapYes($params)
    {
        $query = Check::find()->alias('a')->select(['a.*','b.project_name'])->LeftJoin('zj_project b','a.pid = b.id')->where(
            ['and' ,
                ['=' , 'a.type' , 3] ,
                ['=' , 'a.status' , 2] ,
            ]
        );

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
            ->andFilterWhere(['like', 'b.project_name', $this->project_name]);
        return $dataProvider;
    }

    public function searchScrapNo($params)
    {
        $query = Check::find()->alias('a')->select(['a.*','b.project_name'])->LeftJoin('zj_project b','a.pid = b.id')->where(
            ['and' ,
                ['=' , 'a.type' , 3] ,
                ['=' , 'a.status' , 3] ,
            ]
        );

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
            ->andFilterWhere(['like', 'b.project_name', $this->project_name]);
        return $dataProvider;
    }

    public function searchScrapNever($params)
    {
        $query = Check::find()->alias('a')->select(['a.*','b.project_name'])->LeftJoin('zj_project b','a.pid = b.id')->where(
            ['and' ,
                ['=' , 'a.type' , 3] ,
                ['=' , 'a.status' , 1] ,
            ]
        );

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => 15 ,
            ] ,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'a.name', $this->name])
            ->andFilterWhere(['like', 'b.project_name', $this->project_name]);
        return $dataProvider;
    }
}
